#include <memory.h>
#include <stdlib.h>
#include <stdio.h>

void testRealloc() {
	char *a;
	int k;
	printf("------------Realloc------------\n");
	for (int j=1; j<20; j++) {
		
		if (j&1==1) {
			k = 59;
		} else {
			k = 27;
		}
		//every time resize arrary, memory uses will not change
		a = (char*) realloc(NULL, k);

		for (int i=0; i<k-1; i++) {
			a[i]= 'A'+i;
		}
		a[k-1] = '\0';
		printf("Memory Location: %8d: %s\n",&a, a);
	}
	free(a);
	
}

void testFree() {
	char *a;
	int k;
	printf("------------Malloc and free------------\n");
	for (int j=1; j<20; j++) {
		
		if (j&1==1) {
			k = 59;
		} else {
			k = 27;
		}
		//every time resize arrary, memory uses will not change
		a = (char*) malloc(k);

		for (int i=0; i<k-1; i++) {
			a[i]= 'A'+i;
		}
		a[k-1] = '\0';
		printf("Memory Location: %8d: %s\n",&a, a);
		free(a);
	}
}
int mymain() {
	testRealloc();
	testFree();
	return 0;
}

//int main() {
	//return mymain();
//}